import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        int min = Integer.MAX_VALUE;
        int max = 0;
        int sum = 0;
        int ret = 0;
        for(int i = 0;i<3*n;i++){
            int m  = sc.nextInt();
            if(i+1%3==0){
                ret += sum-min-max;
                sum = 0;
                min = Integer.MAX_VALUE;
                max = 0;
            }
            if(m<min){
                min = m;
            }
            if(m>max){
                max = m;
            }
            sum+= m;
        }
        System.out.println(ret);
    }
}
